import { Component, Injector, ViewChild, ViewEncapsulation } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { AppConsts } from '@shared/AppConsts';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/common/app-component-base';
import { HttpClient } from '@angular/common/http';
import { EntityDtoOfInt64, UserListDto, TaskServiceProxy } from '@shared/service-proxies/service-proxies';
import { FileDownloadService } from '@shared/utils/file-download.service';
import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent';
import { Paginator } from 'primeng/components/paginator/paginator';
import { Table } from 'primeng/components/table/table';
import { finalize } from 'rxjs/operators';

@Component({
  selector: 'app-outsourcingworkflow',
  templateUrl: './outsourcingworkflow.component.html',
  encapsulation: ViewEncapsulation.None,
  styleUrls: ['./outsourcingworkflow.component.css'],
  animations: [appModuleAnimation()]
})
export class OutsourcingWorkflowComponent extends AppComponentBase {

  @ViewChild('dataTable') dataTable: Table;
  @ViewChild('paginator') paginator: Paginator;

  filterText = '1';
  selectedPermission = '';
  role = '';
  onlyLockedUsers = false;
  constructor(
    injector: Injector,
    private _taskServiceProxy: TaskServiceProxy,
    private _activatedRoute: ActivatedRoute,
    private _httpClient: HttpClient
  ) {
    super(injector);
    this.filterText = this._activatedRoute.snapshot.queryParams['filterText'] || '';
  }



  exportToExcel(): void {
    // this._taskServiceProxy.getTaskForModel(
    //     this.filterText,
    //     this.primengTableHelper.getSorting(this.dataTable),
    //     this.primengTableHelper.getMaxResultCount(this.paginator, event),
    //     this.primengTableHelper.getSkipCount(this.paginator, event),
    //     )
    //     .subscribe(result => {
    //         this._fileDownloadService.downloadTempFile(result);
    //     });
  }


  getTasks(event?: LazyLoadEvent) {
    if (this.primengTableHelper.shouldResetPaging(event)) {
      this.paginator.changePage(0);

      return;
  }
  this.primengTableHelper.showLoadingIndicator();

  this._taskServiceProxy.getTaskForModel(
    this.filterText,
  'code',
    this.primengTableHelper.getMaxResultCount(this.paginator, event),
    this.primengTableHelper.getSkipCount(this.paginator, event),
).pipe(finalize(() => this.primengTableHelper.hideLoadingIndicator())).subscribe(result => {
    this.primengTableHelper.totalRecordsCount = result.totalCount;
    this.primengTableHelper.records = result.items;
    console.log(result);
    this.primengTableHelper.hideLoadingIndicator();
});
  }


}
